package org.shiwen.week12.answer;

public class Q6 {
    public static void main(String[] args) {
        System.out.println(leastCommonMultiple(44, 60));
        System.out.println(GreatestCommonDivisor(44, 60));
    }

    public static int leastCommonMultiple(int n, int m) {
        int result = m*n;//默认结果为两数相乘
        int min = 0;//确定最小值
        if(n<=m){
            min = n;
        }else {
            min = m;
        }
        for (int i = 1; i <= min; i++) {//确定循环次数
            if(n%i==0 && m%i==0){//判断是否是公约数
                result = result/i;
                n = n/i;
                m = m/i;
                i = 1;
            }
        }
        return result;
    }

    public static int GreatestCommonDivisor(int n, int m) {
        return m*n/leastCommonMultiple(n, m);
    }
}
